<template>
  <el-container>
    <!-- 页面头部区域 -->
    <el-header>
      <span class="title">朱酱的后台管理系统</span>
      <el-button style="float:right;margin-top:10px;" type="danger" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <!-- 页面侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px' ">
        <div class="toggle_collapse" @click="changeCollapse">| | |</div>
        <el-menu
          :default-active="pathStatus"
          router
          :collapse-transition="false"
          :collapse="isCollapse"
          background-color="#333744"
          unique-opened
          text-color="#fff"
          active-text-color="#409eff"
        >
          <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i :class="menuIcon[item.id]" style="margin-right:10px;"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item
              @click="savePathStatus('/'+i.path)"
              :index="'/'+i.path"
              v-for="i in item.children"
              :key="i.id"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{i.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 页面主题区域 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  // 组件名称
  name: "demo", // 组件参数 接收来自父组件的数据
  props: [],
  components: {},
  data() {
    return {
      menuList: [],
      menuIcon: {
        125: "iconfont icon-0kehutongji",
        103: "iconfont icon-qunzi",
        101: "iconfont icon-hudiejie",
        102: "iconfont icon-shangyi",
        145: "iconfont icon-huangguan"
      },
      isCollapse: false,
      pathStatus: ""
    };
  },
  computed: {},
  watch: {},
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    //获得左侧菜单栏
    async getMenu() {
      const { data: res } = await this.$axios.get("menus");
      if (res.meta.status !== 200)
        return this.$message.error("获取左侧列表失败");
      this.menuList = res.data;
    },
    changeCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    savePathStatus(path) {
      window.sessionStorage.setItem("path", path);
      this.pathStatus = path;
    }
  },
  beforeCreate() {},
  created() {},
  beforeMount() {},
  mounted() {
    this.getMenu();
    this.pathStatus = window.sessionStorage.getItem("path");
  }
};
</script> 
<style scoped>
.el-header,
.el-footer {
  background-color: #373d41;
  color: #333;
}

.el-aside {
  background-color: #333744;
  color: #333;
}

.el-container {
  height: 100%;
}
.title {
  color: #fff;
  font-weight: bold;
  font-size: 36px;
  float: left;
}
.el-menu {
  border-right: none;
}
.toggle_collapse {
  background: #4a5064;
  text-align: center;
  color: #fff;
  font-size: 13px;
  border-radius: 3px;
}
</style>
